<?php

/**
 * This is the model class for table "event".
 *
 * The followings are the available columns in table 'event':
 * @property integer $id
 * @property string $name
 * @property string $time
 * @property string $place
 * @property integer $id_type
 * @property integer $id_host
 *
 * The followings are the available model relations:
 * @property Typeevent $idType
 * @property Host $idHost
 */
class Event extends CActiveRecord
{
    const TYPE_XAHOI=1;
    const TYPE_GIAODUC=2;
    const TYPE_GIAITRI=3;
    const TYPE_SUCMANHSO=4;
    const TYPE_GIOITINH=5;
    const TYPE_ANNINH=6;
    const TYPE_THETHAO=7;
    const TYPE_NHANAI=8;
    const TYPE_KINHDOANH=9;
    const TYPE_VANHOA=10;
    const TYPE_TINHYEU=11;
    const TYPE_SUCKHOE=12;
    const TYPE_OTO_XEMAY=13;
    
	/**
	 * Returns the static model of the specified AR class.
	 * @return Event the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'event';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, time, place, id_type', 'required'),
			//array('id_type, id_host', 'numerical', 'integerOnly'=>true),
			array('name, place', 'length', 'max'=>200),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, time, place, id_type', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idType' => array(self::BELONGS_TO, 'Typeevent', 'id_type'),
			'idHost' => array(self::BELONGS_TO, 'Host', 'id_host'),
            'comments' => array(self::HAS_MANY, 'Comment', 'event_id'),
            'commentCount' => array(self::STAT, 'Comment', 'event_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'time' => 'Time',
			'place' => 'Place',
			'id_type' => 'Type Event',
			'id_host' => 'Id Host',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('time',$this->time,true);
		$criteria->compare('place',$this->place,true);
		$criteria->compare('id_type',$this->id_type);
		$criteria->compare('id_host',$this->id_host);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
    
    public function getTypeEvent ()
    {
        return array (
            self::TYPE_ANNINH=>'An ninh',
            self::TYPE_GIAITRI=>'Giai tri',
            self::TYPE_GIAODUC=>'Giao duc',
            self::TYPE_GIOITINH=>'Gioi tinh',
            self::TYPE_KINHDOANH=>'Kinh doanh',
            self::TYPE_NHANAI=>'Nhan ai',
            self::TYPE_OTO_XEMAY=>'Oto xe may',
            self::TYPE_SUCKHOE=>'Suc khoe',
            self::TYPE_SUCMANHSO=>'Suc manh so',
            self::TYPE_THETHAO=>'The thao',
            self::TYPE_TINHYEU=>'Tinh yeu',
            self::TYPE_VANHOA=>'Van hoa',
            self::TYPE_XAHOI=>'Xa hoi',
        );
    }
    
   
}